﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Student_AddStudent : System.Web.UI.Page
{
    private Client client;
    private Student newStudent = new Student();

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnSearch_OnClick(object sender,EventArgs e)
    {
        if (txtStudentId.Text == null || txtStudentId.Text == "")
            Response.Write("Please input a valid student Id to proceed.");
        else
        {
            client = new Client();
            Student student = client.ViewStudent(System.Convert.ToInt32(txtStudentId.Text));
            txtResidency.Text = student.getResidency();
            txtFirstName.Text = student.getFirstName();
            txtMiddleName.Text = student.getMiddleName();
            txtLastName.Text = student.getLastName();
            txtGender.Text = student.getGender();
            txtAddress.Text = student.getAddress();
            txtCollege.Text = student.getCollege();
            txtContactNo.Text = student.getContactNo().ToString();
            txtProgramCode.Text = student.getProgramCode();
            txtMajorCode.Text = student.getMajorCode();
            txtScholarship.Text = student.getScholarship();
            //Set Limitations for the student to 
            //Edit their data - Lakhi
            txtScholarship.ReadOnly = true;
            txtScholarship.Enabled = false;
            txtCollege.ReadOnly = true;
            txtCollege.Enabled = false;
            txtProgramCode.ReadOnly = true;
            txtProgramCode.Enabled = false;
            txtMajorCode.ReadOnly = true;
            txtMajorCode.Enabled = false;
            newStudent = student;
            Session["StudentData"] = newStudent;
            newStudent.setStudentId(System.Convert.ToInt32(txtStudentId.Text));
            txtStudentId.ReadOnly = true;
            txtStudentId.Enabled = false;
            btnUpdateStudent.Enabled = true;
            btnSearch.Enabled = false;
        }
    }

    protected void btnUpdateStudent_Click(object sender, EventArgs e)
    {
        if (txtStudentId.Text == null || txtStudentId.Text == "")
            Response.Write("Please input a valid student Id to proceed.");
        else
        {
            client = new Client();
            newStudent = (Student)Session["StudentData"];
            newStudent.setStudentId(System.Convert.ToInt32(txtStudentId.Text));
            newStudent.setFirstName(txtFirstName.Text);
            newStudent.setMiddleName(txtMiddleName.Text);
            newStudent.setLastName(txtLastName.Text);
            newStudent.setGender(txtGender.Text);
            newStudent.setAddress(txtAddress.Text);
            newStudent.setResidency(txtResidency.Text);
            newStudent.setCollege(txtCollege.Text);
            newStudent.setContactNo(System.Convert.ToInt32(txtContactNo.Text));
            newStudent.setProgCode(txtProgramCode.Text);
            newStudent.setMajorCode(txtMajorCode.Text);
            newStudent.setScholarshipType(txtScholarship.Text);
            if (client.UpdateStudent(newStudent))
                Response.Write("Successfully Updated Student " + txtStudentId.Text);
            else
                Response.Write("Please Try Again..");
        }
    }

    protected void btnClear_Click(object sender, EventArgs e)
    {
        Session["StudentData"] = null;
        Response.Redirect("stdUpdateStudentInfo.aspx");
    }

    
};